package com.hfzy.ihk.web.freeswitchCall.conf;

import com.hfzy.ihk.common.support.redis.RedisConfig;
import com.hfzy.ihk.common.web.mvc.CommonMvcConfigurer;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * Created by Administrator on 2018/1/16.
 *
 * @author wws
 */
@Configuration
@Import(RedisConfig.class)
public class MvcConfig extends CommonMvcConfigurer implements WebMvcConfigurer {

    //freeswitch录音文件绝对路径
    @Value("${freeswitch.recordFileDiskPath}")
    private String recordFilePath;

    //对外访问的url
    @Value("${freeswitch.web.recordFileUrl}")
    private String  recordFileUrl;

    /**
     * 为freeswitch录音文件添加映射
     * @param registry
     */
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
                    //https://aicall.ihk.cn:9443/fscall/freeswitchRecord/ 20190318/a7295421-7aa1-4216-be20-88b13e400ff5.wav
// ----> file:/cloudcall_file/rec_20051/freeswitchRecordFile/ 20190318/a7295421-7aa1-4216-be20-88b13e400ff5.wav
       //挂载50硬盘
        registry.addResourceHandler(recordFileUrl+"**")
                .addResourceLocations("file:"+recordFilePath);


        registry.addResourceHandler(recordFileUrl.substring(0,recordFileUrl.lastIndexOf("/"))+"51/**")
                .addResourceLocations("file:"+recordFilePath.replace("50","51"));

    }

}
